package com.nondo.rdp.finance.endpoint.api.app.stock;

import com.nondo.rdp.core.model.View;
import com.nondo.rdp.finance.service.MarketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

/**
 * 股票行情API处理接口
 */
@RestController("apiStockMarket")
@RequestMapping("/api/stock/market")
public class MarketEndpoint {

    @Autowired
    MarketService marketService;

    @Autowired
    RestTemplate restTemplate;

    @RequestMapping("/index")
    public View<Map<String, Object>> index() {
        return marketService.marketIndex();
    }

    @RequestMapping("/list/updown")
    public View upList(@RequestBody Map<String, Object> asharesBean) {

        return marketService.marketListUpdown(asharesBean);
    }

    @RequestMapping("/info")
    public View<Map<String, Object>> marketInfo(@RequestBody Map<String, Object> marketBean) {


//        HttpHeaders requestHeaders = new HttpHeaders();
//        requestHeaders.add(WebSecurityUtils.AUTHENTICATION, auth);
//        requestHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);
//        HttpEntity<MarketBean> requestEntity = new HttpEntity<MarketBean>(marketBean, requestHeaders);
//
//        ResponseEntity<View> responseEntity = restTemplate.exchange("http://rdp-stock/api/stock/market/info", HttpMethod.POST, requestEntity, View.class);
//
//        View viewResponseEntity = responseEntity.getBody();
        return marketService.marketInfo(marketBean);
    }

    @RequestMapping("/real")
    public View<Map<String, Object>> real(@RequestBody Map<String, Object> marketBean) {


        return marketService.marketReal(marketBean);
    }

    @RequestMapping("/trend")
    public View<Map<String, Object>> trend(@RequestBody Map<String, Object> marketBean) {


        return marketService.marketTrend(marketBean);
    }

    @RequestMapping("/kline")
    public View<Map<String, Object>> kline(@RequestBody Map<String, Object> marketBean) {


        return marketService.marketKline(marketBean);
    }
    
    @RequestMapping("/concept/updown")
    public View conceptList(@RequestBody Map<String, Object> asharesBean) {

        return marketService.marketConceptListUpdown(asharesBean);
    }
}
